/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: AliceMana
 * Date: 2023-01-01
 * Time: 0:35
 */
// https://leetcode.cn/problems/search-insert-position/submissions/
public class Solution {
    public static int searchInsert(int[] nums, int target) {
        if (target == nums[0] || nums[0] > target) {
            return 0;
        }

        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == target) {
                return i;
            } else if (nums[i] < target && i < nums.length-1 &&nums[i+1] > target) {
                return i+1;
            }
        }
        return nums.length;
    }

    public static void main(String[] args) {
        int[] arr = {1,3};
        System.out.println(searchInsert(arr, 3));
    }
}
